<?php
class Student
{
    // 新增：status属性（存储学生年级，如Freshman、Junior、Senior）
    private $status;
    private $surname;
    private $first_name;
    private $emails;
    private $grades;

    // 构造函数修改：新增$status参数，用于初始化年级属性
    function __construct($surname, $first_name, $status)
    {
        $this->surname = $surname;
        $this->first_name = $first_name;
        $this->status = $status; // 初始化年级属性
        $this->emails = array();
        $this->grades = array();
    }

    // 保留前序提交的方法：添加邮箱、成绩、计算平均分
    function add_email($which, $address)
    {
        $this->emails[$which] = $address;
    }

    function add_grade($grade)
    {
        $this->grades[] = $grade;
    }

    function average()
    {
        $total = 0;
        foreach ($this->grades as $value)
            $total += $value;
        return $total / count($this->grades);
    }

    // toString方法修改：新增输出status（年级）信息
    function toString()
    {
        // 新增：在姓名后拼接年级（如 "Albert Einstein (75) Freshman"）
        $result = $this->first_name . ' ' . $this->surname . ' (' . $this->average() . ') ' . $this->status;
        $result .= "\n";
        foreach ($this->emails as $which => $what) {
            $result .= "\n";
            $result .= $which . ': ' . $what . "\n";
        }
        return '<pre>' . $result . '</pre>';
    }
}